package com.yskj.mwk.utils;

import com.qcloud.cos.COSClient;
import com.qcloud.cos.ClientConfig;
import com.qcloud.cos.auth.BasicCOSCredentials;
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.http.HttpProtocol;
import com.qcloud.cos.model.GetObjectRequest;
import com.qcloud.cos.model.ObjectMetadata;
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingRequest;
import com.qcloud.cos.model.ciModel.auditing.ImageAuditingResponse;
import com.qcloud.cos.region.Region;

import java.io.File;

public class QcloudUtil {

    public static void main(String[] args) {
        // 1 初始化用户身份信息（secretId, secretKey）。
        COSClient cosClient = getCosClient("AKIDbHoHckhV8brvmSxcDi1763sUxELGzUmw", "X7YoriokaQUVP7eiiW8WhiYBamlX6Rbc", "ap-guangzhou");
        // 2 调用要使用的方法。
        getAISuperResolution(cosClient);
        cosClient.shutdown();
    }

    public static COSClient getCosClient(String secretId, String secretKey, String _region) {
        COSCredentials cred = new BasicCOSCredentials(secretId, secretKey);
        Region region = new Region(_region);
        ClientConfig clientConfig = new ClientConfig(region);
        clientConfig.setCheckRequestPath(false);
        return new COSClient(cred, clientConfig);
    }

    public static void getAISuperResolution(COSClient client) {
        //图片所在bucket名称
        String bucketName = "xiaoediy-koutu-1334189972";
        //图片在bucket中的相对位置，比如根目录下file文件夹中的demo.png路径为file/demo.png
        //使用detect-url参数时 这里设置为空字符串  部分接口有限制 key和detect-url不可同时存在
        String key = "";
        GetObjectRequest getObj = new GetObjectRequest(bucketName, key);
        //具体参数请参考API
        getObj.putCustomQueryParameter("ci-process", "AIPicMatting");
        getObj.putCustomQueryParameter("detect-url", "https://yskj.wscapp.com/mwk/upload/image/avatar/2025/02/25/11361f56-2cd2-4e05-86b8-f5f203e3ede1.jpg");
        ObjectMetadata object = client.getObject(getObj, new File("demo.png"));
        System.out.println(object.getContentLength());
    }
}
